home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / all shapes ƒ / all shapes.c next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  8.3 KB  |  256 lines  |  [TEXT/KAHL]

  1. /*
  2.     All Shapes.c
  3.     
  4.     "All Shapes" creates, manipulates, and draws all of the QuickDraw™ GX primitive shapes. As each shape is created,
  5.     it is added to "gthePage". This shape represents the contents of the window. 
  6.     
  7.     This file contains the calls that an application needs to make for the "graphics shell" to work correctly.
  8.  
  9.     NOTES:
  10.     • This file requires the following files to run correctly:
  11.         "graphics shell.c", "ColorLibrary.c", "FontLibrary.c", "GraphicsDebugLibrary.c",
  12.         "QDLibrary.c", "TransformLibrary.c".
  13.         
  14.     • This file prints the "best" in landscape mode.
  15.  
  16.  
  17.     Change History:
  18.  
  19.        4/96    bob        Updated #includes to support changed GX Library names.
  20.                     Changed fixed to Fixed.
  21.                     Updated the above note regarding the files needed to run, and copyright date.
  22.  
  23.     ©1992 - 1996  Apple Computer, Inc.
  24.     All rights reserved.
  25. */
  26.  
  27. #include <events.h>
  28. #include <windows.h>
  29.  
  30. #include "FontLibrary.h"
  31. #include "GraphicsLibraries.h"
  32. #include <GXEnvironment.h>
  33. #include <GXErrors.h>
  34. #include "QDLibrary.h"
  35. #include "graphics shell.h"
  36.  
  37. //
  38. //  Set up the title and size of the window 
  39. //
  40. Str255         gWindowTitle = "\pQuickDraw™ GX Primitive Shapes...";
  41. Rect         gWindowQDRect  = {50, 15, 475, 590};
  42.  
  43. //
  44. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  45. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  46. //    With  gGraphicsHeapSize set to 85k, I had 11 free blocks left in the graphics gxHeap. Sounds good to me.
  47. //
  48. long        gGraphicsHeapSize = 85;
  49.  
  50.  
  51. //
  52. //    Every time you create a new shape, it is added to "gthePage". We can then pass this shape to the GX Print Manager.
  53. //    It will then print the entire page.
  54. //
  55. gxShape         gthePage;    
  56.  
  57.  
  58.  
  59. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  60. //
  61. //    In this function we gxInitialize the CommonColors Library, gObjectCount, gShapesInPicture, and gthePage.
  62. //
  63. void DoInitialization(gWindow)
  64. WindowPtr gWindow;
  65. {
  66.      gxShape         theLine, theRect, theCurve, thePath, theText, thePolygon, theBitmap;    
  67.     gxLine            lineGeometricData = {ff(25), ff(25), ff(125), ff(125)};
  68.     gxRectangle     rectGeometricData = {ff(25), ff(25), ff(75), ff(75)};    
  69.     gxCurve         curveGeometricData = {ff(25), ff(25), ff(275), ff(75), ff(125), ff(125)};    
  70.     long             tripleBumpGeometricData[] = {    1, // number of contours
  71.                                                        6, // number of points
  72.                                                        0xff000000,
  73.                                                           0, 0, 
  74.                                                           ff(75),  0, 
  75.                                                           ff(5), ff(50), 
  76.                                                           ff(75),  ff(100),  
  77.                                                          0,  ff(100), 
  78.                                                           ff(75), ff(50)};
  79.                                                                   
  80.     long             starGeometricData[] = {    1,  //  number of contours 
  81.                                             5 , //  number of points  
  82.                                                ff(60), 0, ff(90), ff(90),  ff(0), ff(30),  ff(120), ff(30), ff(0), ff(90)};   //  the points 
  83.     gxRectangle     theTextBounds;
  84.     gxColor         textColor;
  85.     Fixed            x,y;
  86.     short            loop;
  87.  
  88.     //
  89.     //     We intialize the CommonColors Library.  This will allow us to set the gxColor of a shape by calling the 
  90.      //     SetShapeCommonColor function. We will need to call DisposeCommonColors in our DoDispose 
  91.      //     function to clean up the world.
  92.      //
  93.      InitCommonColors();
  94.     
  95.     //
  96.     //     Create the "gthePage" shape. We set the unique items attribute to make sure that each item added to the
  97.     //     picture has a unique reference. If this attribute was not set, we would not see all six Q's rotated.
  98.     //     We would only see the last "Q" rotated; not all 6 pieces.        
  99.     //
  100.     gthePage = GXNewShape(gxPictureType);
  101.     GXSetShapeAttributes(gthePage, gxUniqueItemsShape);
  102.     
  103.     //
  104.     //      From this gxPoint on, this function adds all of the GX primitives to our picture -  gthePage
  105.     //
  106.  
  107.     //
  108.     //     Create a line
  109.     //
  110.     theLine = GXNewLine (&lineGeometricData);
  111.     GXSetShapePen (theLine, ff(12));    
  112.     GXSetPictureParts(gthePage, 0, 0, 1, &theLine, nil, nil, nil);
  113.     GXDisposeShape(theLine);  
  114.  
  115.     //
  116.     //     Create a rectangle which is: red & is draw with it's frame.
  117.     //
  118.     theRect = GXNewRectangle(&rectGeometricData); 
  119.      SetShapeCommonColor (theRect, red);
  120.     GXSetShapeFill (theRect, gxClosedFrameFill);
  121.     GXMoveShapeTo (theRect,  ff(150), ff(25));
  122.         
  123.     GXSetPictureParts(gthePage, 0, 0, 1, &theRect, nil, nil, nil);
  124.     GXDisposeShape(theRect);  
  125.  
  126.     //
  127.     //     Create a curve which has: a 3.25 pen thickness
  128.     //
  129.     theCurve = GXNewCurve(&curveGeometricData); 
  130.                     
  131.     //     The fl marco converts floating gxPoint #'s to fixed gxPoint.
  132.     GXSetShapePen(theCurve, fl(3.25));
  133.     GXMoveShapeTo (theCurve,  ff(210), ff(25));
  134.         
  135.     GXSetPictureParts(gthePage, 0, 0, 1, &theCurve, nil, nil, nil);
  136.     GXDisposeShape(theCurve);  
  137.  
  138.     //
  139.     //     Create a path which has: a 2 pen thickness, it's gxColor is green, and it's drawn with it's frame 
  140.     //
  141.     thePath = GXNewPaths((gxPaths *) tripleBumpGeometricData);
  142.     GXSetShapeFill (thePath, gxClosedFrameFill);
  143.      GXSetShapePen(thePath, ff(2));
  144.     SetShapeCommonColor (thePath, green);
  145.  
  146.     GXMoveShapeTo (thePath,  ff(390), ff(25));
  147.         
  148.     GXSetPictureParts(gthePage, 0, 0, 1, &thePath, nil, nil, nil);
  149.     GXDisposeShape(thePath);  
  150.  
  151.     //
  152.     // Create a character "GX" which is: colored in hsv space and it is rotated 15 degrees - six times via the left bottom corner.
  153.     //
  154.     theText = GXNewText(2,(unsigned char*)"GX",  nil);
  155.     SetShapeCommonFont(theText, timesFont);
  156.     GXSetShapeTextSize(theText, ff(120));
  157.     GXMoveShapeTo (theText,  ff(15), ff(225));
  158.  
  159.     // Create an hsv gxColor space and set up the initial colors
  160.     textColor.space                     = gxHSVSpace;
  161.     textColor.profile                     = nil;
  162.     textColor.element.hsv.hue             = 0x7400;
  163.     textColor.element.hsv.saturation     = 0xFFFF;
  164.     textColor.element.hsv.value         = 0xFFFF;
  165.  
  166.     // Get the bounds of "theText" and determine the bottom left corner
  167.     GXGetShapeBounds(theText, 0L, &theTextBounds);
  168.     x = theTextBounds.left;      
  169.     y = theTextBounds.bottom;
  170.         
  171.     // Rotate "theText" 15 degrees - 6 times. Add each letter to the picture.
  172.     for (loop = 0; loop < 6; loop++) {
  173.         GXSetShapeColor(theText, &textColor);
  174.         GXSetShapeAttributes(theText, gxMapTransformShape);
  175.         GXRotateShape(theText, ff(15), x, y);
  176.                     
  177.         GXSetPictureParts(gthePage, 0, 0, 1, &theText, nil, nil, nil);
  178.         
  179.        textColor.element.hsv.hue += 0x0940;
  180.     }
  181.     GXDisposeShape(theText);  
  182.  
  183.     //
  184.     //     Create a polygon which has the following features: yellow, drawn with a pen = 3, and skew it in the vertical direction by 0.5 
  185.     //
  186.     thePolygon = GXNewPolygons((gxPolygons *) starGeometricData);
  187.     GXSetShapeFill(thePolygon, gxEvenOddFill);
  188.     GXSetShapePen (thePolygon, ff(3));
  189.     SetShapeCommonColor (thePolygon, yellow);
  190.     GXMoveShapeTo (thePolygon,  ff(240), ff(110));
  191.     GXSkewShape(thePolygon, 0, fl(0.5), 0, 0);
  192.                     
  193.     GXSetPictureParts(gthePage, 0, 0, 1, &thePolygon, nil, nil, nil);
  194.     GXDisposeShape(thePolygon);  
  195.  
  196.     //
  197.     //     Retrieve a bitmap from the resource fork and skew it in the horizontal direction by 2.
  198.     //
  199.     theBitmap = GetPixMapShape(128);
  200.     GXValidateShape (theBitmap);
  201.  
  202.     GXSkewShape(theBitmap, ff(2), 0, 0, 0);
  203.     GXMoveShapeTo (theBitmap,  ff(290), ff(190));
  204.                     
  205.     GXSetPictureParts(gthePage, 0, 0, 1, &theBitmap, nil, nil, nil);
  206.     GXDisposeShape(theBitmap);  
  207. }
  208.  
  209.  
  210. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  211. //
  212. //    Draw the contents of "gthePage". 
  213. // 
  214. void DoDraw(gWindow)
  215. WindowPtr gWindow;
  216. {
  217.       GXDrawShape (gthePage);
  218. }
  219.  
  220.  
  221. void DoClick( orgMouseLoc, theWindow )
  222. gxPoint        orgMouseLoc;
  223. WindowPtr     theWindow;
  224. {
  225. }
  226.  
  227.  
  228.  
  229. /*------ DoDispose -------------------------------------------------------------------------------------*/
  230.  
  231. void DoDispose(gWindow)
  232. WindowPtr gWindow;
  233. {
  234.     /**  
  235.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  236.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  237.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  238.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  239.         can turn notices on in this file by setting gDebugging = TRUE (above).
  240.     **/
  241.     GXDisposeShape(gthePage);  
  242.      GXDisposeShape(gWindowBoundsShape);  
  243.        DisposeCommonColors();
  244.        DisposeWindow(gWindow);
  245. }
  246.     
  247.  
  248.  
  249.  
  250. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  251.  
  252. void DoIdle(gWindow)
  253. WindowPtr gWindow;
  254. {
  255. }
  256.